package com.example.txjc.Activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;

import com.example.txjc.Util.MyVideoView;
import com.example.txjc.Util.ToastUtil;
import com.example.txjc.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class TakeVideoActivity extends Activity {
    @BindView(R.id.normalroomVideo)
    Button normalroomVideo;
    @BindView(R.id.video)
    MyVideoView video;
    String videopath;
    public static final int RECORD_SYSTEM_VIDEO = 100;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_take_video);
        ButterKnife.bind(this);


    }
    @OnClick(R.id.normalroomVideo)
    public void onvideoClick(){
        startActivityForResult(new Intent(TakeVideoActivity.this,VideoActivity.class),RECORD_SYSTEM_VIDEO);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if(requestCode==RECORD_SYSTEM_VIDEO){
                if (data == null) {
                    ToastUtil.show(TakeVideoActivity.this, "未获取视频数据");
                    return;
                }
                videopath = data.getStringExtra("path");
                Uri uri = Uri.parse(videopath);
                // ToastUtil.show(AddNormalRoomActivity.this, videopath);
                MediaController c = new MediaController(this);
                c.setVisibility(View.VISIBLE);
                video.setMediaController(c);
                video.setVideoURI(uri);
                video.start();
                video.requestFocus();
            }
        }
    }
}
